#include<bits/stdc++.h>
using namespace std;
long long n,t,a[250],anss,dp[250][250][250];
long long dfs(long long i,long long ai,long long bi)
{
	if(i==n+1)
		return 0;
	if(dp[i][ai][bi]!=-1)
		return dp[i][ai][bi];
	long long f=dfs(i+1,i,bi);
	long long s=dfs(i+1,ai,i);
	if(a[ai]==a[i])
		f+=a[i];
	if(a[bi]==a[i])
		s+=a[i];
	dp[i][ai][bi]=max(f,s);
	return dp[i][ai][bi];
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%lld",&t);
	while(t--)
	{
		memset(dp,-1,sizeof dp);
		anss=0;
		scanf("%lld",&n);
		for(long long i=1;i<=n;i++)
			scanf("%lld",a+i);
		printf("%lld\n",dfs(1,0,0));
	}
	return 0;
}
